package com.vcs.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.RequestAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.ognl.OgnlValueStack;
import com.opensymphony.xwork2.util.ValueStack;
import com.vcs.dao.SearchDAO;
import com.vcs.dao.SearchDAOImpl;
import com.vcs.domain.Job;
import com.vcs.domain.QuickSearch;

@SuppressWarnings("serial")
public class SearchAction extends ActionSupport implements ModelDriven<QuickSearch>, RequestAware{

	private static final Log log = LogFactory.getLog(SearchAction.class);
	QuickSearch quickSearch = new QuickSearch();
	SearchDAO searchDao = new SearchDAOImpl(); 
	List<Job> jobList = new ArrayList<Job>();
	Map<String, Object> request = new HashMap<String,Object>();
	
	@Override
	public QuickSearch getModel(){
		return quickSearch;
	}
	
	public String quickSearch(){
		log.trace("quickSearch()...");
		
		jobList = (List<Job>) searchDao.quickSearchJobs(quickSearch);
		log.trace("Jobs matching criteria: " + jobList);
		request.put("jobList", jobList);
		
		return SUCCESS;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}
	
}
